let pkgs = PackageSet::new([]);
let cx = try!(Context::new("compile", &resolve, &srcs, &pkgs, &mut cfg,
Layout::at(root.get_absolute_target_dir()),
- None));
+ None, &pkg));
// And finally, clean everything out!
for target in pkg.get_targets().iter() {
/// Extra environment variables that were passed to compilations and should
/// be passed to future invocations of programs.
pub extra_env: HashMap<String, Option<String>>,
+
+ /// Top-level package that was compiled
+ pub package: Package,
}
impl Compilation {
- pub fn new() -> Compilation {
+ pub fn new(pkg: &Package) -> Compilation {
Compilation {
libraries: HashMap::new(),
native_dirs: HashMap::new(),
tests: Vec::new(),
binaries: Vec::new(),
extra_env: HashMap::new(),
+ package: pkg.clone(),
}
}
impl<'a, 'b> Context<'a, 'b> {
pub fn new(env: &'a str, resolve: &'a Resolve, sources: &'a SourceMap,
deps: &'a PackageSet, config: &'b mut Config<'b>,
- host: Layout, target: Option<Layout>)
+ host: Layout, target: Option<Layout>,
+ root_pkg: &Package)
-> CargoResult<Context<'a, 'b>> {
let (target_dylib, target_exe) =
try!(Context::filename_parts(config.target()));
target_exe: target_exe,
host_dylib: host_dylib,
requirements: HashMap::new(),
- compilation: Compilation::new(),
+ compilation: Compilation::new(root_pkg),
})
}
config: &'a mut Config<'a>)
-> CargoResult<Compilation> {
if targets.is_empty() {
- return Ok(Compilation::new())
+ return Ok(Compilation::new(pkg))
}
debug!("compile_targets; targets={}; pkg={}; deps={}", targets, pkg, deps);
});
let mut cx = try!(Context::new(env, resolve, sources, deps, config,
- host_layout, target_layout));
+ host_layout, target_layout, pkg));
let mut queue = JobQueue::new(cx.resolve, deps, cx.config);
// First ensure that the destination directory exists
if options.compile_opts.env == "bench" { return Ok(None) }
- let mut libs = package.get_targets().iter().filter_map(|target| {
+ let mut libs = compile.package.get_targets().iter().filter_map(|target| {
if !target.get_profile().is_doctest() || !target.is_lib() {
return None
}
.arg("-p").arg("b"),
execs().with_status(0));
})
+
+test!(selective_testing_with_docs {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.d1]
+ path = "d1"
+ "#)
+ .file("src/lib.rs", r#"
+ /// ```
+ /// not valid rust
+ /// ```
+ pub fn foo() {}
+ "#)
+ .file("d1/Cargo.toml", r#"
+ [package]
+ name = "d1"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("d1/src/lib.rs", "");
+ p.build();
+
+ assert_that(p.process(cargo_dir().join("cargo")).arg("test")
+ .arg("-p").arg("d1"),
+ execs().with_status(0)
+ .with_stdout(format!("\
+{compiling} d1 v0.0.1 ({dir})
+{running} target[..]deps[..]d1[..]
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+{doctest} d1
+
+running 0 tests
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
+
+", compiling = COMPILING, running = RUNNING, dir = p.url(),
+ doctest = DOCTEST).as_slice()));
+})